### Project Data ###

# main targets
TARGET = mtm_rentals

# test targets
TEST_TARGETS = rentals_test car_test customer_test bill_test list_test

# compiler and linker flags
CC ?= gcc
CCFLAGS += -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG
LDFLAGS += -std=c99

# additional libs
MTM_EX2_LIB_DIR = .
MTM_EX2_LIB = mtm
LDFLAGS += -L$(MTM_EX2_LIB_DIR) -l$(MTM_EX2_LIB)

# object files for modules
OBJ_FILES = rentals.o car.o customer.o bill.o list.o
PROG_OBJ_FILES = $(OBJ_FILES) main.o
TEST_OBJ_FILES = rentals_test.o car_test.o customer_test.o bill_test.o list_test.o

### Target Definitions ###

# handles objects
%.o: %.c
	$(CC) $(CCFLAGS) -c $< -o $@

# handles the target itself
$(TARGET): $(PROG_OBJ_FILES)
	$(CC) -o $@ $(PROG_OBJ_FILES) $(LDFLAGS)

# handles test targets
tests: rentals_test car_test customer_test bill_test list_test

rentals_test: rentals_test.o $(OBJ_FILES)
	$(CC) -o $@ $(OBJ_FILES) rentals_test.o $(LDFLAGS)
car_test: car_test.o $(OBJ_FILES)
	$(CC) -o $@ $(OBJ_FILES) car_test.o $(LDFLAGS)
customer_test: customer_test.o $(OBJ_FILES)
	$(CC) -o $@ $(OBJ_FILES) customer_test.o $(LDFLAGS)
bill_test: bill_test.o $(OBJ_FILES)
	$(CC) -o $@ $(OBJ_FILES) bill_test.o $(LDFLAGS)
list_test: list_test.o $(OBJ_FILES)
	$(CC) -o $@ $(OBJ_FILES) list_test.o $(LDFLAGS)

# compiles everything
all: $(TARGET) $(TEST_TARGETS)


unit_test: $(TEST_TARGETS)
	./rentals_test
	./car_test
	./customer_test
	./bill_test
	./list_test

# cleans everything
clean:
	rm -rf $(PROG_OBJ_FILES) $(TEST_OBJ_FILES) $(TARGET) $(TEST_TARGETS)
